
class HomeController < ApplicationController

  def index
    fetch_home_data
    @floors = Floor.all
    @wikis = Wiki.where("").order('Updated_at DESC').limit(7)
    @designers = User.joins(:user_roles).where("user_roles.role_id = ?", Role.get_designer_role.id).limit(5)
    @best_selling = Product.where(is_top: true).limit(mobile? ? 3 : 5)
    @design_cases = DesignCase.find_by_sql("SELECT DISTINCT ON (user_id) user_id, id from design_cases where is_uploaded = true limit 3")

    set_common_seo_meta('home', 'index')
  end

  def get_baidu_ads
    render layout: nil
  end

  def get_baidu_ads_for_mobile
    render layout: nil
  end

  def demo
    fetch_home_data
    @products = Product.all
  end

  def get_floor
    @floors = Floor.all
    render json: { floors: @floors }
  end

  private

  def fetch_data
    @categories = Category.grouped_data
  end

end
